import sys
import numpy as np
out = open(sys.argv[3],'w')
f1 = open(sys.argv[1],'r')
x=np.zeros((23,300000000), dtype = int)
line = f1.readline()
while line:
    if line.strip().split('\t')[0].split('_')[0] == 'Un':
        break
    chr = int(line.strip().split('\t')[0].split('_')[0])
    pos = int(line.strip().split('\t')[1])
    x[chr,pos:pos+2500]=1
    line = f1.readline()

f2 = open(sys.argv[2],'r')
line = f2.readline()
while line:
    chr = int(line.strip().split('\t')[3].split('_')[0][3:])
    pos1 = int(line.strip().split('\t')[3].split('_')[1].split(',')[0])
    pos2 = int(line.strip().split('\t')[3].split('_')[1].split(',')[-1])
    if x[chr,pos1] > 0 or x[chr,pos2] > 0:
        out.write(line)
    line = f2.readline()
f1.close()
f2.close()
out.close()
